package com.austin.leetcode.algorithm.LeetCodeArray;

/**
 * @author Linbizhao
 * @description: 删除有序数组的重复项
 * @since 2024/1/10 17:47
 */
public class SolutionRemoveDuplicates {

    /**
     * 双指针法
     *
     * @param nums
     * @return
     */
    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        if (len == 0) {
            return 0;
        }
        int low = 1, high = 1;
        while (high < len) {
            if (nums[high] != nums[high - 1]) {
                nums[low] = nums[high];
                low ++;
            }
            high++;
        }
        return low;
    }
}
